<template>
  <div class="gdetails">
    <div class="sheng_qi" v-show="flag"></div>
    <!-- 头部 -->
    <div class="top">
      <router-link to="" @click.native="fanHui()">&lt;</router-link>
      <div class="top_title">商品详情</div>
    </div>

    <div
      class="zhong_jian"
    >
      <!-- 轮播 -->
      <div class="lun_bo">
        <swiper ref="mySwiper" :options="swiperOptions">
          <swiper-slide>
            <img :src="obj.img" alt="" />
          </swiper-slide>
          <swiper-slide>
            <img :src="obj.img" alt="" class="img" />
          </swiper-slide>
          <swiper-slide>
            <img :src="obj.img" alt="" class="img1" />
          </swiper-slide>
        </swiper>
      </div>
      <!-- 信息 -->
      <div class="xinxi">
        <div class="xx_title">
          <p>
            <del v-if="obj.title1!=''">￥{{obj.title1}}</del>
            <ins :class="{ztYan:obj.title1==''}">￥{{obj.title2}}</ins>
          </p>
          <p>{{ obj.title }}</p>
        </div>
        <ul>
          <li>
            <div>
              <span>活动: </span>
              <span> [最新优惠券]</span>
            </div>
            <router-link to=""> 立即领取 > </router-link>
          </li>
          <li @click="tanqi()">
            <span>选择商品规格</span>
            <span>></span>
          </li>
        </ul>
      </div>
      <!-- 交易记录 -->
      <div class="jiao_yi">
        <div>
          <span>交易记录</span>
          <div>
            <span>购买0+</span>
            <span>浏览0+</span>
          </div>
        </div>
      </div>
      <div class="fen_ge">
        <hr />
        <p>继续拖动，查看商品信息</p>
      </div>
      <div class="sh_xixi">
        <ul class="shop_xinxi">
          <li @click="xiang_qing()">
            <span :class="{ color: flag1 }">详情</span>
          </li>
          <li @click="pin_lun()">
            <span :class="{ color: !flag1 }">评论(0)</span>
          </li>
        </ul>
        <div class="can_shu" v-show="flag1">
          <img :src="obj.img" alt="" width="100%" />
        </div>
        <div class="pin_lun" v-show="!flag1">
          <div class="sai_pl">
            <ul>
              <li @click="qunBu()" :class="{ bgColor: flag2 == 1 }">全部</li>
              <li @click="haoPin()" :class="{ bgColor: flag2 == 2 }">
                好评(0)
              </li>
              <li @click="zhongPin()" :class="{ bgColor: flag2 == 3 }">
                中评(0)
              </li>
              <li @click="chaPin()" :class="{ bgColor: flag2 == 4 }">
                差评(0)
              </li>
              <li @click="youTu()" :class="{ bgColor: flag2 == 5 }">有图(0)</li>
            </ul>
          </div>
          <div class="yan_lun"></div>
        </div>
      </div>

      <div class="xuan_xiang">
        <ul>
          <li>
            <router-link to="/Cart" @click.native="gouWu()">
              <span class="iconfont icon-gouwuche"></span>
              <span>购物车</span>
            </router-link>
          </li>
          <li @click="shouCang()" :class="{'huang':flag4}">
            <span class="iconfont icon-shoucang4"></span>
            <span>关注</span>
          </li>
        </ul>
        <ul>
          <li @click="tanqi()">加入购物车</li>
          <li @click="tanqi1()">立即购买</li>
        </ul>
      </div>
    </div>

    <div class="sq_nr">
      <span class="guan_bi" @click="xiaoshi($event)">X</span>
      <div class="sq_xinxi">
        <div class="xinxi_title">
          <img :src="obj.img" alt="" />
          <div>
            <p>{{obj.title}}</p>
            <div>
              <del v-if="obj.title1!=''">￥{{obj.title1}}</del>
            <ins :class="{ztYan:obj.title1==''}">￥{{obj.title2}}</ins>
            </div>
          </div>
        </div>
        <div class="shu_liang">
          <span>数量</span>
          <div>
            <button @click="jian()">-</button>
            <span>{{num}}</span>
            <button @click="add()">+</button>
          </div>
        </div>
      </div>
      <router-link to="/Cart" @click.native="gouWu()" v-show="flag3 == true">
        加入购物车
      </router-link>
      <router-link
        :to="{name:'Balance',params:{id:'000'}}"
        @click.native="ljGm()"
        v-show="flag3 == false"
      >
        立即购买
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      obj:'',
      num:1,
      qunJu:'',
      flag: false,
      flag1: true,
      flag2: 1,
      flag3: true,
      jsShu:'',
      msg:'gdetails',
      // 收藏开关
      flag4:false,
      swiperOptions: {
        autoplay: true,
        loop: true, //循环播放
      },
    };
  },
  methods: {
    fanHui(){
      window.history.go(-1)
    },
    tanqi() {
      this.flag3 = true;
      this.flag = !this.flag;
      $(".sq_nr").animate(
        {
          bottom: 0,
        },
        700
      );
    },
    tanqi1() {
      this.flag3 = false;
      this.flag = !this.flag;
      $(".sq_nr").animate(
        {
          bottom: 0,
        },
        700
      );
    },
    xiaoshi() {
      $(".sq_nr").animate(
        {
          bottom: "-5.706667rem",
        },
        700,
        () => {
          this.flag = !this.flag;
        }
      );
    },
    xiang_qing() {
      this.flag1 = true;
    },
    pin_lun() {
      this.flag1 = false;
    },
    qunBu() {
      this.flag2 = 1;
    },
    haoPin() {
      this.flag2 = 2;
    },
    zhongPin() {
      this.flag2 = 3;
    },
    chaPin() {
      this.flag2 = 4;
    },
    youTu() {
      this.flag2 = 5;
    },
    // 购物车 
    jian() {
      if (this.num > 1) {
        this.num--;
      }
    },
    add() {
      this.num++;
    },
    gouWu() {
      // console.log(this.obj);
      this.qunJu={
        img:this.obj.img,
        title:this.obj.title,
        dazhe:this.obj.title1,
        price:this.obj.title2,
        num:this.num,
        flag:false
      }
      this.$store.commit('add',this.qunJu)
      // this.$store.getters.genXin
    },
    ljGm() {
      this.jsShu=[{
        img:this.obj.img,
        title:this.obj.title,
        dazhe:this.obj.title1,
        price:this.obj.title2,
        num:this.num,
        flag:true
      }]
      this.$store.commit('ljGm',this.jsShu);
      // this.$router.push({path:'/Balance/'+this.msg});
    },
    shuJu(){
      this.obj=JSON.parse(localStorage.getItem('xqXx'));
    },
    shouCang(){
      this.flag4=!this.flag4;
      if(this.flag4){
        
      }
    }
  },
  mounted(){
    setTimeout(()=>{
      this.shuJu();
    },50)
  }
};
</script>

<style lang="less" scoped>
.ztYan{
      color:#000 !important;
    }
.gdetails {
  margin-bottom: 50px;
  position: relative;
  .sheng_qi {
    height: 100%;
    position: absolute;
    left: 0px;
    right: 0px;
    top: 0px;
    bottom: 0px;
    z-index: 50;
    background-color: rgba(0, 0, 0, 0.5);
  }
  .zhong_jian {
    margin-top: 45px;
    position: relative;
    .lun_bo {
      background: #ffffff;
      width: 100%;
      height: 8.533333rem !important;
      div {
        height: 8.533333rem;
        overflow: hidden;
        img {
          width: 100%;
          height: 8.533333rem !important;
        }
        .img {
          width: 100%;
          height: 100%;
          transform: rotate(90deg);
        }
        .img1 {
          width: 100%;
          height: 100%;
          transform: rotate(-90deg);
        }
      }
    }
  }
  .xinxi {
    // margin-top: 0.133333rem;
    background: #ffffff;
    padding: 0px 0.266667rem;
    > .xx_title {
      > :first-child {
        color: #de0a2b;
        text-align: center;
        font-size: 14px;
        >del{
          color: #a9a9a9;
        }
        >ins{
          color: #de0a2b;
          text-decoration: none;
        }
      }
      > :last-child {
        color: #353535;
        margin-top: 0.133333rem;
        font-size: 14px;
        text-align: center;
      }
    }
    > ul {
      margin-top: 0.533333rem;
      li {
        align-items: center;
        display: flex;
        justify-content: space-between;
        height: 0.8rem;
        font-size: 13px;
        color: #a9a9a9;
        border-top: 1px solid #cccccc;
      }
      > :first-child {
        > div {
          > :last-child {
            color: #de0a2b;
          }
        }
        > a {
          color: #a9a9a9;
        }
      }
    }
  }
  .jiao_yi {
    height: 1.28rem;
    padding: 0px 0.266667rem;
    margin-top: 0.266667rem;
    background: #ffffff;
    > div {
      height: 100%;
      display: flex;
      flex-flow: row;
      justify-content: space-between;
      font-size: 13px;
      color: #a9a9a9;
      align-items: center;
      > div {
        :first-child {
          color: #de0a2b;
          margin-right: 0.133333rem;
        }
      }
    }
  }
  .fen_ge {
    height: 0.853333rem;
    background: #f4f4f4;
    line-height: 0.853333rem;
    display: flex;
    flex-flow: column;
    justify-content: center;
    align-items: center;
    position: relative;
    > hr {
      position: absolute;
      top: 50%;
      width: 70%;
      z-index: 1;
      transform: translateY(-50%);
      border: 1px solid #cccccc;
      background: #cccccc;
    }
    > p {
      z-index: 2;
      // width: 3.866667rem;
      text-align: center;
      font-size: 12px;
      background: #f4f4f4;
      color: #a9a9a9;
    }
  }
  .sh_xixi {
    padding: 0px 0.266667rem;
    background: #ffffff;
    .shop_xinxi {
      height: 0.8rem;
      display: flex;
      flex-flow: row;
      border-bottom: 1px solid #f4f4f4;
      li {
        width: 50%;
        display: flex;
        flex-flow: row;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        span {
          line-height: 0.8rem;
          display: inline-block;
          height: 100%;
        }
        .color {
          color: #de0a2b;
          border-bottom: 1px solid #de0a2b;
        }
      }
    }
    .can_shu {
      padding-top: 0.133333rem;
      display: flex;
      flex-flow: column;
      justify-content: center;
      align-items: center;
    }
    .pin_lun {
      padding: 0px 0.266667rem;
      .sai_pl {
        height: 1.466667rem;
        > ul {
          height: 100%;
          display: flex;
          flex-flow: row;
          justify-content: space-around;
          align-items: center;
          > li {
            color: #353535;
            background-color: #f4f4f4;
            text-align: center;
            padding: 0.133333rem 0.186667rem;
            font-size: 13px;
            border-radius: 4px;
          }
          .bgColor {
            background-color: #e64461;
            color: #ffffff;
          }
        }
      }
      .yan_lun {
        height: 0.8rem;
        border-top: 1px solid #eeeeee;
      }
    }
  }
  .xuan_xiang {
    z-index: 3;
    position: fixed;
    height: 50px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    border-top: 1px solid #cccccc;
    display: flex;
    align-items: center;
    background: #ffffff;
    > ul {
      height: 100%;
    }
    
    > :first-child {
      width: 33.3%;
      display: flex;
      align-items: center;
      >.huang{
          > :first-child {
            color: #f5a623 !important;
          }
      }
      > li {
        height: 100%;
        display: flex;
        flex-flow: column;
        align-items: center;
        justify-content: center;
        width: 50%;
        color: #666666;
        > a {
          height: 100%;
          width: 100%;
          display: flex;
          flex-flow: column;
          align-items: center;
          justify-content: center;
          > :first-child {
            color: #666666;
            font-size: 18px;
          }
            > :last-child {
              color: #666666;
              font-size: 13px;
            }
        }
      }
      > :first-child {
        border-right: 1px solid #cccccc;
      }
      
      >:last-child{
        > :first-child {
            color: #666666;
            font-size: 18px;
          }
            > :last-child {
              color: #666666;
              font-size: 13px;
            }
      }
    }
    > :last-child {
      height: 100%;
      display: flex;
      width: 66.8%;
      text-align: center;
      line-height: 50px;
      > li {
        height: 100%;
        width: 50%;
        font-size: 16px;
        color: #ffffff;
      }
      > :first-child {
        background: #e64461;
      }
      > :last-child {
        background: #c20430;
      }
    }
  }
}

.sq_nr {
  z-index: 60;
  background: #ffffff;
  position: fixed;
  bottom: -5.733333rem;
  width: 100%;
  .guan_bi {
    cursor: pointer;
    font-size: 16px;
    position: absolute;
    right: 0.133333rem;
    top: 0.133333rem;
    color: #353535;
    border: 1px solid;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    text-align: center;
    line-height: 20px;
    font-family: inherit;
  }
  .sq_xinxi {
    padding: 0.266667rem 0.266667rem;
    .xinxi_title {
      width: 100%;
      display: flex;
      height: 1.466667rem;
      border-bottom: 1px solid #eeeeee;
      > img {
        margin-top: -0.933333rem;
        width: 2.266667rem;
        height: 2.266667rem;
        margin-right: 0.133333rem;
        border-radius: 5px;
        border: 1px solid #eeeeee;
      }
      > div {
        display: flex;
        flex-flow: column;
        justify-content: space-evenly;
        width: 100%;
        > p {
          width: 63%;
          color: #353535;
          font-size: 15px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        > div {
          del {
            color: #a9a9a9;
            font-size: 12px;
            margin-right: 0.133333rem;
          }
          ins {
            font-size: 14px;
            font-weight: 800;
            color: #de0a2b;
            text-decoration: none;
          }
        }
      }
    }
    .shu_liang {
      border-bottom: 1px solid #eeeeee;
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 1.68rem;
      > span {
        font-size: 16px;
        font-weight: 800;
        color: #a9a9a9;
      }
      > div {
        display: flex;
        align-items: center;
        button {
          text-align: center;
          line-height: 0.56rem;
          outline: none;
          border: none;
          width: 0.56rem;
          height: 0.56rem;
          border-radius: 2px;
          background: #f1f1f1;
          color: #878787;
          font-size: 16px;
        }
        span {
          font-size: 14px;
          text-align: center;
          line-height: 0.56rem;
          background: #f1f1f1;
          display: inline-block;
          margin: 0px 0.133333rem;
          height: 0.56rem;
          width: 0.8rem;
        }
      }
    }
  }
  > a {
    text-align: center;
    line-height: 1.173333rem;
    font-size: 16px;
    display: block;
    margin-top: 0.186667rem;
    height: 1.173333rem;
    color: #ffffff;
    background: #e64461;
  }
}
</style>